home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / deskbar-applet / handlers / iswitch-window.py < prev    next >
Encoding:
Python Source  |  2007-04-09  |  1.9 KB  |  79 lines

  1. from gettext import gettext as _
  2. from gettext import ngettext
  3. from deskbar.defs import VERSION
  4. import wnck, gtk
  5. import deskbar.Handler, deskbar.Match, deskbar
  6. import re
  7. import cgi
  8.  
  9. HANDLERS = {
  10.     "ISwitchWindowHandler" : {
  11.         "name": _("Window Switcher"),
  12.         "description": _("Switch to an existing window by name."),
  13.  
  14.         "categories" : {
  15.             "windows"    : {
  16.                 "name": _("Windows"),
  17.                 }
  18.             },
  19.         "version": VERSION,
  20.             
  21.         }
  22.     }
  23.  
  24. class ISwitchWindowMatch(deskbar.Match.Match):
  25.     def __init__(self, handler, window=None, pixbuf=None, **args):
  26.         deskbar.Match.Match.__init__ (self, handler, **args)
  27.         self.name = cgi.escape(self.name)
  28.         self._icon = pixbuf
  29.         self._window = window
  30.  
  31.     def get_verb(self):
  32.         return _("Switch to <b>%(name)s</b>")
  33.  
  34.     def action(self, text=None):
  35.         if self._window.is_active():
  36.             return
  37.         
  38.         try:
  39.             time = gtk.get_current_event().time
  40.         except:
  41.             print "WARNING, iSwitchWindow : Using bogus timestamp."
  42.             time = gtk.get_current_event_time()
  43.         
  44.         
  45.         if hasattr(self._window.get_workspace(), 'activate') and self._window.get_workspace() != self._window.get_screen().get_active_workspace():
  46.             self._window.get_workspace().activate(time)
  47.  
  48.         self._window.activate(time)
  49.  
  50.     def get_category(self):
  51.         return "windows"
  52.  
  53.     def get_hash(self, text=None):
  54.         return self.name
  55.  
  56.     def serialize(self):
  57.         return None
  58.     
  59.     def skip_history(self):
  60.         return True
  61.  
  62. class ISwitchWindowHandler(deskbar.Handler.Handler):
  63.     def __init__(self):
  64.         deskbar.Handler.Handler.__init__(self, "panel-window-menu.png")
  65.  
  66.     def query(self, query):
  67.         results = []
  68.         query = query.lower()
  69.         for w in wnck.screen_get_default().get_windows_stacked():
  70.                 if w.is_skip_tasklist():
  71.                         continue
  72.                 
  73.                 for name in (w.get_name().lower(), w.get_application().get_name().lower()):
  74.                         if name.find(query) != -1:
  75.                                 results.append(ISwitchWindowMatch(self, name=name, window=w, pixbuf=w.get_mini_icon()))
  76.                                 break
  77.  
  78.         return results
  79.